package com.example.springdemo.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;


//错误处理
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Object globalErrorHandler(HttpServletRequest request, Exception e ) {
        Map<String, Object> retMap = new HashMap<>();
        retMap.put("code", 500);
        retMap.put("message", e.getMessage());
        return retMap;
    }
}
